<?php

	include("../config.php");
	include(INCLUDEDIR."core.php");
	
	db::Connect();
	
	//if(!isset($_GET['term'])) exit();
	$q = $_GET['term'];
	$e = intval($_GET['e']);
		
		
	if(strlen($q)<2) exit();
	
	$query = "	SELECT zonas.id_zona, zonas.zona FROM zonas WHERE zona like '%$q%' ";
	if($e>0) $query.=" AND id_estado = '$e'";

	$result = mysql_query($query);
	$posts = array();
	if($result && mysql_num_rows($result)>0) {
		while($row = mysql_fetch_assoc($result)) {
			$posts[] = array( "id" => $row['id_zona'], 
					"label" => $row['zona'], 
					"value" => $row['zona']);
			
		}
	}
	
	echo(json_encode($posts));
?>